package com.two.lbms.lyq.controller;


import com.two.lbms.base.BaseController;
import com.two.lbms.base.ResultInfo;
import com.two.lbms.dao.BookInfoMapper;
import com.two.lbms.dao.ReaderMapper;
import com.two.lbms.lyq.query.LoadDate;
import com.two.lbms.lyq.query.Queryreturn;
import com.two.lbms.lyq.query.Their;
import com.two.lbms.lyq.service.RetrunBookService;
import com.two.lbms.utils.AssertUtil;
import com.two.lbms.vo.BackList;
import com.two.lbms.vo.BookInfo;
import com.two.lbms.vo.Reader;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.val;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.http.HttpRequest;
import java.util.Map;

@Controller
@RequestMapping("return")
public class ReturnTheBookController extends BaseController {
    @Resource
    private RetrunBookService retrunBookService;

    @Resource
    private ReaderMapper readerMapper;

    @Resource
    private BookInfoMapper bookInfoMapper;


    /**
     * 分页多条件查询用户列表
     * 判断当前读者是否存在,调用读者service，查看当前读者是否存在
     *当前用户存在，调用通过用户id查询归还表back book
     * 乐字节：专注线上IT培训
     * 答疑老师微信：lezijie
     * @param queryreturn
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> selectByParams(Queryreturn queryreturn) {
        //queryreturn为不为空和里面的值为不为空不一样
        // Queryreturn(readername=null, bookname=null, readerId=null, bookId=null),仍然有属性值
        //
        System.out.println(queryreturn);

        System.out.println("开始多条件查询");
        Map<String,Object> map = retrunBookService.queryBackListByParams(queryreturn);
        System.out.println(map);
        return  map;




    }


    @RequestMapping("Borrow")
    public String toBorrow(){
        //转发到还书页面
        return "leipage/readerback";
    }


    @RequestMapping("updateandadd")
    public String updateoradd(Integer BackListid, HttpServletRequest request){
        //从还书页面转发到数据添加或者修改页面
        // 判断saleChanceId是否为空
        if (BackListid != null) {
            System.out.println("BackListid"+BackListid);
            Their their = retrunBookService.selectByid(BackListid);
            System.out.println(their);
            // 将数据设置到请求域中
            request.setAttribute("their",their);
        }
        return "leipage/add/add";
    }


    @RequestMapping("add")
    @ResponseBody
    public ResultInfo add(LoadDate loadDate){
        ResultInfo resultInfo;
        //查询借阅表中的是否有该读者的借阅记录
        System.out.println(loadDate);
        //存在开始添加还书记录
        retrunBookService.addbacklist(loadDate);
        return success("添加成功");
    }



    @RequestMapping("update")
    @ResponseBody
    public  ResultInfo update(LoadDate loadDate,Integer BackListId ){
        System.out.println("开始修改");
        System.out.println(BackListId);
        ResultInfo resultInfo;
        System.out.println(loadDate);
        retrunBookService.updatebackList(loadDate,BackListId);
        return success("修改成功");
    }


    @RequestMapping("delete")
    @ResponseBody
    public ResultInfo delete(Integer[] BackListid){
        ResultInfo resultInfo;
        retrunBookService.deleteByid(BackListid);
        return success("营销机会数据删除成功！");
    }






}
